package middle;

public class Solution_80 {
    public int removeDuplicates(int[] nums) {
        int index = 1, firstIndex = 0;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] == nums[firstIndex]) {
                if (i - firstIndex <= 1) {
                    nums[index++] = nums[i];
                }
            } else {
                firstIndex = i;
                nums[index++] = nums[i];
            }
        }
        return index;
    }

    public static void main(String[] args) {
        Solution_80 model = new Solution_80();
//        int[] ints = {1,1,1,2,2,3};
        int[] ints = {0,0,1,1,1,1,2,3,3};
        int i = model.removeDuplicates(ints);
        for (int i1 = 0; i1 < i; i1++) {
            System.out.print(ints[i1] + " ");
        }
        System.out.println();
    }
}
